package com.sita.tboard.advertisement;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.Serializable;

/**
 * Created by xiaodong on 16/3/4.
 */
public class AdModel implements Serializable {
    public String id;
    public String bitmap;
    public String linkUri;
    public int playCount;
    public AdModel(String mId, String mBitmap, String mLinkUri, int mPlayCount){
        id = mId;
        bitmap = mBitmap;
        linkUri = mLinkUri;
        playCount = mPlayCount;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        AdModel adModel = (AdModel) o;

        if (playCount != adModel.playCount) return false;
        if (id != null ? !id.equals(adModel.id) : adModel.id != null) return false;
        if (bitmap != null ? !bitmap.equals(adModel.bitmap) : adModel.bitmap != null) return false;
        return !(linkUri != null ? !linkUri.equals(adModel.linkUri) : adModel.linkUri != null);

    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (bitmap != null ? bitmap.hashCode() : 0);
        result = 31 * result + (linkUri != null ? linkUri.hashCode() : 0);
        result = 31 * result + playCount;
        return result;
    }

    public String toString(){
        Gson gson = new GsonBuilder()
                .serializeNulls()
                .create();
        return gson.toJson(this);
    }

    public static AdModel parse(String string){
        Gson gson = new GsonBuilder()
                .serializeNulls()
                .create();
        AdModel adModel = gson.fromJson(string, AdModel.class);
        return adModel;
    }
}
